<?php

namespace slinks\common\io;

use slinks\common\Finder\Finder;

/**
 * Reads a filesystem and allows the given IFileSystemVisitor to process each node in the filesystem being read. 
 * @author navid
 *
 */
class FileSystemReader {
    /* @var $fileSystemVisitor IFileSystemVisitor */

    private $fileSystemVisitor;

    /**
     * Constructs a new FileSystemReader with the given IFileSystemVisitor
     * @param IFileSystemVisitor $fileSystemVisitor
     */
    public function __construct(IFileSystemVisitor $fileSystemVisitor) {
        $this->fileSystemVisitor = $fileSystemVisitor;
    }

    /**
     * Reads all files and directories from the filesystem as specified by the finder.
     * @param Finder $finder the Finder configured to read the files/directories you want to visited.
     */
    public function read(Finder $finder) {

        // loop thru all files specified by finder
        foreach ($finder as $file) {
            $this->fileSystemVisitor->visit($file);
        }
    }

}

